package com.zzs.team.Controller;

import com.google.gson.Gson;
import com.zzs.team.Entity.TeamShow;
import com.zzs.team.Service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@ResponseBody
public class LikeController {

    @Autowired
    LikeService likeService;

    @PostMapping("/like/addLike")
    public Map addLike(String userid,Integer teamid){
        Map result = new HashMap();
        try{
            System.out.println(userid);
            System.out.println(teamid);
            likeService.addLike(userid,teamid);
            result.put("msg",1);    //成功返回1
        }catch (Exception e){
            e.printStackTrace();
            result.put("msg",0);   //失败返回0
        }
        return result;
    }

    @PostMapping("/like/cancleLike")
    public Map cancleLike(String userid,Integer teamid){
        Map map = new HashMap();
        try {
            likeService.cancleLike(userid,teamid);
            map.put("msg",1);
        }catch (Exception e){
            e.printStackTrace();
            map.put("msg",0);
        }
        return map;
    }

    /**
     * 查询用户收藏的teamID
     * @param userID
     * @return 返回的是整数列表
     */
    @GetMapping("/like/getUserLikes")
    public Map getUserLikes(String userID){
        Map map = new HashMap();
        try {
            List<Integer> likes = likeService.getUserLikes(userID);
            map.put("likes",likes);
            map.put("msg",1);
        }catch (Exception e){
            e.printStackTrace();
            map.put("msg",0);
        }
        return map;
    }

    @PostMapping("/like/getUserLikesTeamShow")
    public Map getUserLikesTeamShow(String userID){
        Map map = new HashMap();
        try{
            List<TeamShow> likes = likeService.getUserLikesTeamShow(userID);
            map.put("likes",likes);
            map.put("msg",1);
        }catch (Exception e){
            e.printStackTrace();
            map.put("msg",0);
        }
        return map;
    }
}
